package com.csun.cmny.provider.controller.rpc;

import com.csun.cmny.provider.model.service.UacGroupFeignApi;
import com.csun.cmny.provider.model.vo.CountVo;
import com.csun.cmny.provider.model.vo.GroupInforVo;
import com.csun.cmny.provider.model.vo.GroupVo;
import com.csun.cmny.provider.model.vo.RpcGroupVo;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.UacGroupService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2021-01-07 14:49
 * @Description:
 */
@Slf4j
@RestController
@Api(value = "API - UacVolunteerFeignClient", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class UacGroupFeignApiClient implements UacGroupFeignApi {

    @Resource
    private UacGroupService uacGroupService;
    @Resource
    private CmnyMessageSource cmnyMessageSource;

    @Override
    public Wrapper<List<RpcGroupVo>> queryGroupList() {

        List<RpcGroupVo> rpcGroupVoList = uacGroupService.queryGroupList();

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), rpcGroupVoList);
    }

    @Override
    public List<GroupInforVo> getAllGroup(Long groupId) {
        return uacGroupService.getAllGroup(groupId);
    }

    /**
     * 查询该机构及子机构信息
     *
     * @param groupId   the group id
     *
     * @return  the rpc group vo list.
     */
    @Override
    public Wrapper<List<GroupVo>> queryGroupListByGroupId(@RequestParam("groupId") Long groupId) {

        List<GroupVo> groupVoList = uacGroupService.queryGroupListByGroupId(groupId);

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), groupVoList);
    }

    /**
     * 查询子机构信息
     *
     * @param groupId   the group id
     *
     * @return  the rpc group vo list
     */
    @Override
    public Wrapper<List<GroupVo>> queryChildListByGroupId(@RequestParam("groupId") Long groupId) {

        List<GroupVo> groupVoList = uacGroupService.queryChildListByGroupId(groupId);

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), groupVoList);
    }

    /**
     * 查询机构类型
     * @param groupId
     * @return
     */
    @Override
    public Wrapper<List<CountVo>> selectType(@RequestParam("groupId") Long groupId) {
        List<CountVo> countVos = uacGroupService.selectType(groupId);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), countVos);
    }


}
